package com.starview.star.compiler.operator;

import com.starview.star.compiler.standard.StandardNames;
import com.starview.star.compiler.util.PrettyPrintDisplay;

@SuppressWarnings("serial")
public class InfixOperator extends Operator
{
  public InfixOperator(String operator, int priority)
  {
    super(operator, priority, OperatorForm.infix);
  }

  public InfixOperator(String operator, int priority, OperatorForm form)
  {
    super(operator, priority, form);
  }

  public InfixOperator(String operator, int priority, int minPriority, OperatorForm form)
  {
    super(operator, form, priority, minPriority);
  }

  public int leftPriority()
  {
    return getPriority() - 1;
  }

  public int rightPriority()
  {
    return getPriority() - 1;
  }

  @Override
  public boolean dominatesLeft(Operator op)
  {
    return op.getPriority() <= leftPriority();
  }

  @Override
  public boolean dominatesRight(Operator op)
  {
    return op.getPriority() <= rightPriority();
  }

  @Override
  public String toLatex()
  {
    return "\\tt " + StandardNames.latexString(getOperator()) + "&" + getPriority() + "&infix";
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    disp.append(StandardNames.META_HASH);
    disp.append(StandardNames.INFIX);
    disp.append("((");
    disp.append(getOperator());
    disp.append("),");
    disp.append(getPriority());
    if (getMinPriority() > 0) {
      disp.append(",");
      disp.append(getMinPriority());
    }
    disp.append(")");
  }
}
